#include "Queue_Lst.h"

CQueue_Lst::CQueue_Lst(void)
{
    m_head = NULL;
    m_tail = NULL;
    m_size = 0;
}

CQueue_Lst::~CQueue_Lst(void)
{
    Clear();
}


void CQueue_Lst::Enqueue(double data)
{
    Node* newNode = new Node();
    newNode->data = data;
    newNode->next = NULL;

    if (NULL == m_tail)
    {
        m_head = m_tail = newNode;
    }
    else
    {
        m_tail->next = newNode;
        m_tail = newNode;
    }

    ++m_size;
}

bool CQueue_Lst::Dequeue(double& data)
{
    if (NULL == m_head)
    {
        return false;
    }

    data = m_head->data;
    Node* headNode = m_head->next;
    delete m_head;

    m_head = headNode;
    --m_size;

    return true;
}

void CQueue_Lst::Clear()
{
    Node* headNode = NULL;
    while (NULL != m_head)
    {
        headNode = m_head->next;
        delete m_head;
        m_head = headNode;
    }

    m_tail = NULL;
    m_size = 0;
}


int CQueue_Lst::GetSize()
{
    return m_size;
}

bool CQueue_Lst::IsEmpty()
{
    return (NULL == m_head);
}

bool CQueue_Lst::GetHead(double& data)
{
    if (NULL == m_head)
    {
        return false;
    }

    data = m_head->data;
    return true;
}